module.exports.first   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
c 0
b 0
f 0
nc 1
dl 11
loc 11
rs 10
nop 1
1 View Code Duplication
const DB = require('../../libraries/db')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
const ModelBase = require('../../model/base')
3
const _ = require('underscore')
4
5
const table = 'mist_product'
6
7
module.exports = {
8
    add: async function (data) {
9
        let res = await ModelBase.execInsert(table, data)
10
        return res;
11
    },
12
13
	list: async function (storeId, filter) {
14
15
		let result = DB.readMysql.select(
16
			'*'
17
		)
18
			.from(table)
19
			.where('store_id', storeId)
20
			.whereNot('status', -1)
21
22
		if (_.has(filter, 'status')) result.where('status', filter.status)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
23
24
		if (_.has(filter, 'category_id')) {
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
25
			// todo
26
		}
27
28
		return await result
29
30
	},
31
32
	first: async function (id) {
33
34
		let result = DB.readMysql.first(
35
			'*'
36
		)
37
			.from(table)
38
			.where('id', id)
39
40
		return await result
41
42
	},
43
44
	edit: async function (data, where, notWhere = {}) {
45
		let result = ModelBase.execUpdate(table, data, where, notWhere)
46
47
		return await result
48
	}
49
50
}
51